#include<iostream>
using namespace std;

typedef struct node{
    node *next;
    int data;
}QNode;


class queue{
public:
    QNode *QH,*QR;
    int tag=0;
    queue();
    ~queue();
    void Insert(int x);
    void Init_queue();
    void show();
    
    void delete_NODE(int x);
    bool Qstate();
};


bool queue::Qstate(){
    if(QH==QR||tag==0){
        cout<<"queue is empty!";
        return false;
    }
    else return true;
}

void queue::show(){

        QNode *p=QH;
        cout<<endl;
        while(p->next!=QH){
            p=p->next;
            cout<<p->data<<"\t";
        }
        cout<<endl;
}

void queue::Insert(int x){
    QNode *s;
    s=new QNode;
    s->data=x;
    s->next=QH;
        QR->next=s;
        QR=s;
        tag++;
}

void queue::Init_queue(){
    QH=QR=new QNode;
    int n,x,i;
    cout<<"input number of elements: ";
    cin>>n;
    cout<<endl;

    for(i=0;i<n;i++){
            cout<<"input no."<<i+1<<" number:";
            cin>>x;
        Insert(x);
    }
}

void queue::delete_NODE(int x){
    QNode *p=QH;
    int findFlag=0;

    while(!findFlag&&p->next){

        p=p->next;
        if(p->next->data==x){
            findFlag=1;
        }
    }
    if(findFlag){
        QNode *q=p->next;
        p->next=q->next;
        delete q;
        tag--;
    }
    else
        cout<<endl<<"no such node!"<<endl;
}


queue::queue(){
    Init_queue();
}
queue::~queue(){
    QNode *p;
    while(QH){
        p=QH;
        QH=QH->next;
        delete p;
    }
    QH=QR=NULL;
}

int main()
{
    queue qu;
    qu.show();
    int n;
    do{
        cout<<endl<<"input the node to delete: ";
        cin>>n;
        qu.delete_NODE(n);
        qu.show();
    }while(qu.Qstate());
}
